
# System containers will require mount points for the following
mkdir -p /dev
mkdir -p /proc
mkdir -p /sys/fs/cgroup
mkdir -p /dev/pts
mkdir -p /proc/self/fd

# In order for the package manager to function /dev/null, /dev/random and
# /dev/urandom must exist. This is is being run here because some images do not
# create /dev/null by default.
[ ! -e /dev/null ] && mknod -m 0666 /dev/null c 1 3
[ ! -e /dev/random ] && mknod -m 0666 /dev/random c 1 8
[ ! -e /dev/urandom ] && mknod -m 0666 /dev/urandom c 1 9

for i in {0..5}; do
  [ ! -e "/dev/pts/$i" ] && mknod -m 0666 "/dev/pts/$i" c 136 $i
done
[ ! -e /dev/pts/ptmx ] && mknod -m 0666 /dev/pts/ptmx c 5 2

[ ! -e /dev/fd ] && ln -s /proc/self/fd /dev/fd
for i in {0..2}; do
  ln -sf /dev/pts/0 /dev/fd/$i
done

#gnupg requires this
mkdir -p /root/.gnupg

# Create the directory where local facts will be stored
mkdir -p /etc/ansible/facts.d

# Create the backups directory
mkdir -p /var/backup

# Create networkd directory
mkdir -p /etc/systemd/network

# Remove the journal directory
rm -rf /var/log/journal || true

# Create the cache resolvers
rm /etc/resolv.conf || true
{% for resolver in nspawn_cache_prep_dns %}
echo "nameserver {{ resolver }}" >> /etc/resolv.conf
{% endfor %}

rm /etc/machine-id || true
rm /var/lib/dbus/machine-id || true
rm /etc/sysctl.d/* || true

mkdir -p /root/.ssh
chmod 700 /root/.ssh

mkdir -p /var/lib/empty
chmod -R 755 /var/lib/empty

if [[ -e "/etc/securetty" ]]; then
  chmod 600 /etc/securetty
fi

chage -I -1 -d -1 -m 0 -M 99999 -E -1 root || true
